package com.itheima.edu.info.manager.dao;

import com.itheima.edu.info.manager.domain.Student;

import java.util.ArrayList;

public class OtherStudentDao implements BaseStudentDao {
   static ArrayList<Student> stus=new ArrayList<>();
    static{
        Student stu1 = new Student("heima001","张三","23","1998-01-01");
        Student stu2 = new Student("heima002","李三","23","1996-01-01");
        Student stu3 = new Student("heima003","王五","24","1997-01-01");
        stus.add(stu1);
        stus.add(stu2);
        stus.add(stu3);
    }
    public  void deleteStudent(String sid) {
        int index = getIndex(sid);
        stus.remove(index);
    }
   public  int getIndex(String sid){
        int index=-1;
       for (int i = 0; i < stus.size(); i++) {
           Student stu = stus.get(i);
           if(stu!=null&&stu.getId().equals(sid)){
               index=i;
               break;
           }
       }
        return index;
   }

    public  void updataStudent(Student student, String sid) {
        int index = getIndex(sid);
            stus.set(index,student);

    }


    public boolean addStudent(Student stu) {
     stus.add(stu);
     return true;
    }

    public Student[] findAllStudent() {
        Student[] students = new Student[stus.size()];
        for (int i = 0; i < stus.size(); i++) {
            Student student = stus.get(i);
            students[i]=student;
        }
        return students;
    }
}
